from datetime import datetime
from typing import Optional
from pydantic import BaseModel, Field
from bson import ObjectId


# # 自定义ObjectId类，用于处理MongoDB的_id字段
# class PyObjectId(ObjectId):
#     @classmethod
#     def __get_validators__(cls):
#         # 定义验证器，用于Pydantic模型验证
#         yield cls.validate
#
#     @classmethod
#     def validate(cls, v):
#         # 验证输入值是否为有效的ObjectId
#         if not ObjectId.is_valid(v):
#             raise ValueError("Invalid ObjectId")
#         return ObjectId(v)
#
#     @classmethod
#     def __modify_schema__(cls, field_schema):
#         # 修改OpenAPI schema，将ObjectId类型显示为string
#         field_schema.update(type="string")
#

